package com.jzr.board.ui.adapter

import android.graphics.Color
import android.graphics.drawable.GradientDrawable
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.LinearLayout
import android.widget.RelativeLayout
import android.widget.TextView
import androidx.annotation.Nullable
import com.blankj.utilcode.utils.EmptyUtils
import com.blankj.utilcode.utils.LogUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.jzr.board.R
import com.jzr.board.bean.PatientListBean
import com.jzr.board.utils.CommonUtil
import com.jzr.board.view.FlikerProgressBar


class PatientListApadter(
    data: MutableList<PatientListBean.DataBean>?
) :
    BaseQuickAdapter<PatientListBean.DataBean, BaseViewHolder>(
        R.layout.item_beadinfo,
        data
    ) {
    private var params = ViewGroup.LayoutParams(200, 300)

    private var sizeTvName: Int? = 0
    private var sizeTv: Int? = 0
    private var sizeTvInfusion: Int? = 0

    init {
        this.params = params
    }

    fun setLayoutParams(params: ViewGroup.LayoutParams?) {
        this.params = params!!
    }

    fun setTextSize(sizeTvName: Int, sizeTv: Int, sizeTvInfusion: Int) {
        this.sizeTvName = sizeTvName
        this.sizeTv = sizeTv
        this.sizeTvInfusion = sizeTvInfusion
    }

    override fun convert(helper: BaseViewHolder?, item: PatientListBean.DataBean?) {

        val rlNo = helper?.getView<RelativeLayout>(R.id.rl_no)
        val itemBg = helper?.getView<RelativeLayout>(R.id.ll_item_patient)
        val tvLevel = helper?.getView<TextView>(R.id.tv_level)
//        val progressBar: FlikerProgressBar = helper?.getView(R.id.round_flikerbar)
        val flEmpty = helper?.getView<FrameLayout>(R.id.fl_empty)
        val llReal = helper?.getView<LinearLayout>(R.id.ll_real)
        val llInfusionStart = helper?.getView<LinearLayout>(R.id.ll_infusion_start)

        if (EmptyUtils.isNotEmpty(item?.nurseLevelBgColor)) {
            itemBg?.setBackgroundColor(
                Color.parseColor(
                    item?.nurseLevelBgColor
                )
            )
        }

        val myGrad = rlNo?.background as GradientDrawable
        val tvBedNo = helper.getView<TextView>(R.id.tv_beadno)
        val tvName = helper.getView<TextView>(R.id.tv_name)
        val tvCureNo = helper.getView<TextView>(R.id.tv_cureNo)
        val tvSex = helper.getView<TextView>(R.id.tv_sex)
        val tvAge = helper.getView<TextView>(R.id.tv_age)
        val tvDoctorname = helper.getView<TextView>(R.id.tv_doctorname)
        val tvNurseName = helper.getView<TextView>(R.id.tv_nurseName)
        val tvNurseName2 = helper.getView<TextView>(R.id.tv_nurseName2)
        val tvDate = helper.getView<TextView>(R.id.tv_date)
        val tvBuytype = helper.getView<TextView>(R.id.tv_buytype)
        val tvInfusionVolume = helper.getView<TextView>(R.id.tv_infusion_volume)
        val tvInfusionVolumeValue =
            helper.getView<TextView>(R.id.tv_infusion_volume_value)
        val tvInfusionSpeed = helper.getView<TextView>(R.id.tv_infusion_speed)
        val tvInfusionSpeedValue = helper.getView<TextView>(R.id.tv_infusion_speed_value)
        val tvInfusionStart = helper.getView<TextView>(R.id.tv_infusion_start)
        val tvEmpty = helper.getView<TextView>(R.id.tv_empty)

        if (item?.bedStatus == 1) {
            //  床位占用状态：0空闲 1使用
            llReal?.visibility = View.VISIBLE
            // llInfusionStart.setVisibility(View.VISIBLE);
            flEmpty?.visibility = View.GONE
//            progressBar.setProgress(50f)
            if (EmptyUtils.isNotEmpty(item.nurseLevelBgColor)) myGrad.setColor(
                Color.parseColor(
                    item.nurseLevelBgColor
                )
            )
            if (EmptyUtils.isNotEmpty(item.name)) tvName.text = CommonUtil.replaceNameX(item.name)
            if (EmptyUtils.isNotEmpty(item.sexText)) tvSex.text = item.sexText
            if (EmptyUtils.isNotEmpty(item.age)) tvAge.text = item.age
            if (EmptyUtils.isNotEmpty(item.cureNo)) tvCureNo.text = "住院号: "+  item.cureNo
            if (EmptyUtils.isNotEmpty(item.inTime)) tvDate.text = item.inTime
            if (EmptyUtils.isNotEmpty(item.nurseLevelName)) tvLevel?.text ="护理等级: "+  item.nurseLevelName
            //tvLevel.setTextColor(Color.parseColor(item.getNurseLevelFontColor()));
            if (EmptyUtils.isNotEmpty(item.bedName)) tvBedNo.text = item.bedName
            if (EmptyUtils.isNotEmpty(item.doctorName)) tvDoctorname.text ="医生: "+ item.doctorName
            if (EmptyUtils.isNotEmpty(item.nurseName)) tvNurseName.text ="责任护士: "+ item.nurseName
            if (EmptyUtils.isNotEmpty(item.nurseName2)) tvNurseName2.text ="值班护士: "+ item.nurseName2
        } else {
            llReal?.visibility = View.GONE
            llInfusionStart?.visibility = View.GONE
            flEmpty?.visibility = View.VISIBLE
            myGrad.setColor(Color.parseColor("#212121"))
        }

        tvBedNo.textSize = sizeTvName?.toFloat()!!
        tvName.textSize = sizeTvName?.toFloat()!!
        tvCureNo.textSize = sizeTv?.toFloat()!!
        tvSex.textSize = sizeTv?.toFloat()!!
        tvAge.textSize = sizeTv?.toFloat()!!
        tvDoctorname.textSize = sizeTv?.toFloat()!!
        tvLevel?.textSize = sizeTv?.toFloat()!!
        tvBuytype.textSize = sizeTv?.toFloat()!!
        tvDate.textSize = sizeTv?.toFloat()!!
        tvInfusionVolume.textSize = sizeTvInfusion?.toFloat()!!
        tvInfusionVolumeValue.textSize = sizeTvInfusion?.toFloat()!!
        tvInfusionSpeed.textSize = sizeTvInfusion?.toFloat()!!
        tvInfusionSpeedValue.textSize = sizeTvInfusion?.toFloat()!!
        tvInfusionStart.textSize = sizeTv?.toFloat()!!
        tvEmpty.textSize = sizeTvName?.toFloat()!!

        tvNurseName2.textSize = sizeTv?.toFloat()!!
        tvNurseName.textSize = sizeTv?.toFloat()!!

        helper.itemView.layoutParams = params

        helper.itemView.setOnClickListener{
            if(onItemClick!=null){
                onItemClick?.onListItemClick(item)
            }
        }

    }

    private var onItemClick: onListItemClick? = null

    interface onListItemClick {
        fun onListItemClick(item: PatientListBean.DataBean?)
    }

    fun onListItemClick(onListItemClick: onListItemClick?) {
        this.onItemClick = onListItemClick
    }

}